package com.ste.client;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.logging.Logger;

public class WriteServer implements Runnable {
	private OutputStream os;
	private View view;
	private static Logger log = Logger.getLogger(WriteServer.class.getName());

	public WriteServer(OutputStream os, View view) {
		this.os = os;
		this.view = view;
	}

	@Override
	public void run() {
		PrintWriter oos = null;
		try {
			oos = new PrintWriter(os, true);
			oos.flush();
			String mes = null;
			while (true) {
				mes = view.getCommandsHandler().clientMessages.getMessage();
				oos.println(mes);
				log.info("client out: " + mes);
			}
		} catch (InterruptedException e) {
		} finally {
			if (oos != null) {
				oos.close();
			}
		}
	}

}
